/*
    Copyright (C) 2025 mio <stigma@disroot.org>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"

#include <tqfileinfo.h>

#include <tdeaboutdata.h>
#include <tdeapplication.h>
#include <tdecmdlineargs.h>

#include "aster.h"

static TDECmdLineOptions options[] = {
    { "play-bluray", I18N_NOOP("Play Blu-ray Disc"), nullptr },
    { "play-dvd", I18N_NOOP("Play DVD Disc"), nullptr },
    { "+[file]", I18N_NOOP("The file(s) to play."), nullptr },
    TDECmdLineLastOption
};

int main(int argc, char **argv)
{
    TDEAboutData about(PROJECT_NAME, I18N_NOOP("Aster"), PROJECT_VERSION, I18N_NOOP("TDE Media Player"),
                       TDEAboutData::License_GPL_V3, "Copyright (C) 2025 mio", nullptr, nullptr, "stigma@disroot.org");

    about.addAuthor("Mio", nullptr, "stigma@disroot.org");

    TDECmdLineArgs::init(argc, argv, &about);
    TDECmdLineArgs::addCmdLineOptions(options);

    TDEApplication app(argc, argv);

    Aster aster;

    TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();

    if (args->isSet("play-bluray")) {
        aster.playBD();
    } else if (args->isSet("play-dvd")) {
        aster.playDVD();
    } else {
        for (size_t i = 0; i < args->count(); ++i) {
            TQString arg = TQFile::decodeName(args->arg(i));
            if (arg.startsWith(".")) {
                /* KURL doesn't play nice with local non-absolute file paths. */
                TQFileInfo info(arg);
                aster.enqueFile(info.absFilePath());
            } else {
                /* Either a remote URL or absolute file path */
                aster.enqueFile(arg);
            }
        }
    }

    aster.show();

    app.setMainWidget(&aster);

    return app.exec();
}
